<?xml version="1.0" encoding='UTF-8'?>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.teragadgets.android.comics.appengine.Comic" %>
<%@ page import="com.teragadgets.android.comics.appengine.PMF" %>

<webcomic>

<%
    PersistenceManager pm = PMF.get().getPersistenceManager();

	int webComicID = Integer.parseInt(request.getParameter("id"));
    String query = "select from " + Comic.class.getName()
					+ " where webComic == webComicParam "
					+ "parameters int webComicParam "
					+ "order by number ";
					
	String order = request.getParameter("order");
	if(order == null || order.equals("desc"))
		query += "desc ";
	
	String start = request.getParameter("start");
	String end = request.getParameter("end");
	if(start != null && end != null)
		query += "range " + Integer.parseInt(start) + "," + Integer.parseInt(end);
	
    List<Comic> comics = (List<Comic>) pm.newQuery(query).execute(webComicID);
    for (Comic c : comics) {
%>
	<comic name="<%= c.getName() %>" number="<%= c.getNumber()%>" url="<%= c.getURL() %>"
			alt="<%=c.getAltText()%>" />
<%
    }
    pm.close();
%>

</webcomic>